home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / !Interfaces / Universal Interfaces 2.0a1 / CIncludes / DatabaseAccess.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-25  |  12.1 KB  |  319 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        DatabaseAccess.h
  3.  
  4.      Copyright:    © 1984-1994 by Apple Computer, Inc.
  5.                  All rights reserved.
  6.  
  7.      Version:    Universal Interfaces 2.0a1.  ETO #15, MPW prerelease.  Sunday, July 17, 1994. 
  8.  
  9.      Bugs?:        If you find a problem with this file, send the file and version
  10.                  information (from above) and the problem description to:
  11.  
  12.                      Internet:    apple.bugs@applelink.apple.com
  13.                      AppleLink:    APPLE.BUGS
  14.  
  15. */
  16.  
  17. #ifndef __DATABASEACCESS__
  18. #define __DATABASEACCESS__
  19.  
  20.  
  21. #ifndef __RESOURCES__
  22. #include <Resources.h>
  23. #endif
  24. /*    #include <Types.h>                                            */
  25. /*        #include <ConditionalMacros.h>                            */
  26. /*    #include <MixedMode.h>                                        */
  27. /*    #include <Files.h>                                            */
  28. /*        #include <OSUtils.h>                                    */
  29.  
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33.  
  34. #if GENERATINGPOWERPC
  35. #pragma options align=mac68k
  36. #endif
  37.  
  38. #ifdef __CFM68K__
  39. #pragma lib_export on
  40. #endif
  41.  
  42.  
  43. enum {
  44.     typeNone                    = 'none',
  45.     typeDate                    = 'date',
  46.     typeTime                    = 'time',
  47.     typeTimeStamp                = 'tims',
  48.     typeDecimal                    = 'deci',
  49.     typeMoney                    = 'mone',
  50.     typeVChar                    = 'vcha',
  51.     typeVBin                    = 'vbin',
  52.     typeLChar                    = 'lcha',
  53.     typeLBin                    = 'lbin',
  54.     typeDiscard                    = 'disc',
  55. /* "dummy" types for DBResultsToText */
  56.     typeUnknown                    = 'unkn',
  57.     typeColBreak                = 'colb',
  58.     typeRowBreak                = 'rowb',
  59. /* pass this in to DBGetItem for any data type */
  60.     typeAnyType                    = 0
  61. };
  62.  
  63. /* infinite timeout value for DBGetItem */
  64. enum {
  65. /* messages for status functions for DBStartQuery */
  66.     kDBUpdateWind                = 0,
  67.     kDBAboutToInit                = 1,
  68.     kDBInitComplete                = 2,
  69.     kDBSendComplete                = 3,
  70.     kDBExecComplete                = 4,
  71.     kDBStartQueryComplete        = 5
  72. };
  73.  
  74. enum {
  75. /* messages for status functions for DBGetQueryResults */
  76.     kDBGetItemComplete            = 6,
  77.     kDBGetQueryResultsComplete    = 7,
  78.     kDBWaitForever                = -1,
  79. /*  flags for DBGetItem  */
  80.     kDBLastColFlag                = 0x0001,
  81.     kDBNullFlag                    = 0x0004
  82. };
  83.  
  84. typedef OSType DBType;
  85.  
  86. typedef struct DBAsyncParamBlockRec DBAsyncParamBlockRec, *DBAsyncParmBlkPtr;
  87.  
  88. /*
  89.         DBCompletionProcPtr uses register based parameters on the 68k and cannot
  90.         be written in or called from a high-level language without the help of
  91.         mixed mode or assembly glue.
  92.  
  93.         In:
  94.          => pb              A1.L
  95. */
  96.  
  97. #if GENERATINGCFM
  98. typedef UniversalProcPtr DBCompletionUPP;
  99. #else
  100. typedef Register68kProcPtr DBCompletionUPP;
  101. #endif
  102.  
  103. struct DBAsyncParamBlockRec {
  104.     DBCompletionUPP                    completionProc;                /* pointer to completion routine */
  105.     OSErr                            result;                        /* result of call */
  106.     long                            userRef;                    /* for application's use */
  107.     long                            ddevRef;                    /* for ddev's use */
  108.     long                            reserved;                    /* for internal use */
  109. };
  110. enum {
  111.     uppDBCompletionProcInfo = kRegisterBased
  112.          | REGISTER_ROUTINE_PARAMETER(1, kRegisterA1, SIZE_CODE(sizeof(DBAsyncParmBlkPtr)))
  113. };
  114.  
  115. #if GENERATINGCFM
  116. #define CallDBCompletionProc(userRoutine, pb)        \
  117.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppDBCompletionProcInfo, (pb))
  118. #else
  119. /* (*DBCompletionProcPtr) cannot be called from a high-level language without the Mixed Mode Manager */
  120. #endif
  121.  
  122. #if GENERATINGCFM
  123. #define NewDBCompletionProc(userRoutine)        \
  124.         (DBCompletionUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBCompletionProcInfo, GetCurrentArchitecture())
  125. #else
  126. #define NewDBCompletionProc(userRoutine)        \
  127.         ((DBCompletionUPP) (userRoutine))
  128. #endif
  129.  
  130. struct ResListElem {
  131.     ResType                            theType;                    /* resource type */
  132.     short                            id;                            /* resource id */
  133. };
  134. typedef struct ResListElem ResListElem;
  135.  
  136. typedef ResListElem *ResListPtr, **ResListHandle;
  137.  
  138. /* structure for query list in QueryRecord */
  139. typedef Handle QueryArray[256];
  140.  
  141. typedef Handle **QueryListHandle;
  142.  
  143. struct QueryRecord {
  144.     short                            version;                    /* version */
  145.     short                            id;                            /* id of 'qrsc' this came from */
  146.     Handle                            queryProc;                    /* handle to query def proc */
  147.     Str63                            ddevName;                    /* ddev name */
  148.     Str255                            host;                        /* host name */
  149.     Str255                            user;                        /* user name */
  150.     Str255                            password;                    /* password */
  151.     Str255                            connStr;                    /* connection string */
  152.     short                            currQuery;                    /* index of current query */
  153.     short                            numQueries;                    /* number of queries in list */
  154.     QueryListHandle                    queryList;                    /* handle to array of handles to text */
  155.     short                            numRes;                        /* number of resources in list */
  156.     ResListHandle                    resList;                    /* handle to array of resource list elements */
  157.     Handle                            dataHandle;                    /* for use by query def proc */
  158.     long                            refCon;                        /* for use by application */
  159. };
  160. typedef struct QueryRecord QueryRecord;
  161.  
  162. typedef QueryRecord *QueryPtr, **QueryHandle;
  163.  
  164. /* structure of column types array in ResultsRecord */
  165. typedef DBType ColTypesArray[256];
  166.  
  167. typedef Handle ColTypesHandle;
  168.  
  169. /* structure for column info in ResultsRecord */
  170. struct DBColInfoRecord {
  171.     short                            len;
  172.     short                            places;
  173.     short                            flags;
  174. };
  175. typedef struct DBColInfoRecord DBColInfoRecord;
  176.  
  177. typedef DBColInfoRecord ColInfoArray[256];
  178.  
  179. typedef Handle ColInfoHandle;
  180.  
  181. /* structure of results returned by DBGetResults */
  182. struct ResultsRecord {
  183.     short                            numRows;                    /* number of rows in result */
  184.     short                            numCols;                    /* number of columns per row */
  185.     ColTypesHandle                    colTypes;                    /* data type array */
  186.     Handle                            colData;                    /* actual results */
  187.     ColInfoHandle                    colInfo;                    /* DBColInfoRecord array */
  188. };
  189. typedef struct ResultsRecord ResultsRecord;
  190.  
  191. typedef pascal OSErr (*DBQueryDefProcPtr)(long *sessID, QueryHandle query);
  192. typedef pascal Boolean (*DBStatusProcPtr)(short message, OSErr result, short dataLen, short dataPlaces, short dataFlags, DBType dataType, Ptr dataPtr);
  193. typedef pascal OSErr (*DBResultHandlerProcPtr)(DBType dataType, short theLen, short thePlaces, short theFlags, Ptr theData, Handle theText);
  194.  
  195. #if GENERATINGCFM
  196. typedef UniversalProcPtr DBQueryDefUPP;
  197. typedef UniversalProcPtr DBStatusUPP;
  198. typedef UniversalProcPtr DBResultHandlerUPP;
  199. #else
  200. typedef DBQueryDefProcPtr DBQueryDefUPP;
  201. typedef DBStatusProcPtr DBStatusUPP;
  202. typedef DBResultHandlerProcPtr DBResultHandlerUPP;
  203. #endif
  204.  
  205. enum {
  206.     uppDBQueryDefProcInfo = kPascalStackBased
  207.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  208.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long*)))
  209.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(QueryHandle))),
  210.     uppDBStatusProcInfo = kPascalStackBased
  211.          | RESULT_SIZE(SIZE_CODE(sizeof(Boolean)))
  212.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(short)))
  213.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(OSErr)))
  214.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
  215.          | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(short)))
  216.          | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(short)))
  217.          | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(DBType)))
  218.          | STACK_ROUTINE_PARAMETER(7, SIZE_CODE(sizeof(Ptr))),
  219.     uppDBResultHandlerProcInfo = kPascalStackBased
  220.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  221.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DBType)))
  222.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
  223.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
  224.          | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(short)))
  225.          | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(Ptr)))
  226.          | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(Handle)))
  227. };
  228.  
  229. #if GENERATINGCFM
  230. #define NewDBQueryDefProc(userRoutine)        \
  231.         (DBQueryDefUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBQueryDefProcInfo, GetCurrentArchitecture())
  232. #define NewDBStatusProc(userRoutine)        \
  233.         (DBStatusUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBStatusProcInfo, GetCurrentArchitecture())
  234. #define NewDBResultHandlerProc(userRoutine)        \
  235.         (DBResultHandlerUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBResultHandlerProcInfo, GetCurrentArchitecture())
  236. #else
  237. #define NewDBQueryDefProc(userRoutine)        \
  238.         ((DBQueryDefUPP) (userRoutine))
  239. #define NewDBStatusProc(userRoutine)        \
  240.         ((DBStatusUPP) (userRoutine))
  241. #define NewDBResultHandlerProc(userRoutine)        \
  242.         ((DBResultHandlerUPP) (userRoutine))
  243. #endif
  244.  
  245. #if GENERATINGCFM
  246. #define CallDBQueryDefProc(userRoutine, sessID, query)        \
  247.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppDBQueryDefProcInfo, (sessID), (query))
  248. #define CallDBStatusProc(userRoutine, message, result, dataLen, dataPlaces, dataFlags, dataType, dataPtr)        \
  249.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppDBStatusProcInfo, (message), (result), (dataLen), (dataPlaces), (dataFlags), (dataType), (dataPtr))
  250. #define CallDBResultHandlerProc(userRoutine, dataType, theLen, thePlaces, theFlags, theData, theText)        \
  251.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppDBResultHandlerProcInfo, (dataType), (theLen), (thePlaces), (theFlags), (theData), (theText))
  252. #else
  253. #define CallDBQueryDefProc(userRoutine, sessID, query)        \
  254.         (*(userRoutine))((sessID), (query))
  255. #define CallDBStatusProc(userRoutine, message, result, dataLen, dataPlaces, dataFlags, dataType, dataPtr)        \
  256.         (*(userRoutine))((message), (result), (dataLen), (dataPlaces), (dataFlags), (dataType), (dataPtr))
  257. #define CallDBResultHandlerProc(userRoutine, dataType, theLen, thePlaces, theFlags, theData, theText)        \
  258.         (*(userRoutine))((dataType), (theLen), (thePlaces), (theFlags), (theData), (theText))
  259. #endif
  260.  
  261. extern pascal OSErr InitDBPack(void)
  262.  FIVEWORDINLINE(0x3F3C, 0x0004, 0x303C, 0x0100, 0xA82F);
  263. extern pascal OSErr DBInit(long *sessID, ConstStr63Param ddevName, ConstStr255Param host, ConstStr255Param user, ConstStr255Param passwd, ConstStr255Param connStr, DBAsyncParmBlkPtr asyncPB)
  264.  THREEWORDINLINE(0x303C, 0x0E02, 0xA82F);
  265. extern pascal OSErr DBEnd(long sessID, DBAsyncParmBlkPtr asyncPB)
  266.  THREEWORDINLINE(0x303C, 0x0403, 0xA82F);
  267. extern pascal OSErr DBGetConnInfo(long sessID, short sessNum, long *returnedID, long *version, Str63 ddevName, Str255 host, Str255 user, Str255 network, Str255 connStr, long *start, OSErr *state, DBAsyncParmBlkPtr asyncPB)
  268.  THREEWORDINLINE(0x303C, 0x1704, 0xA82F);
  269. extern pascal OSErr DBGetSessionNum(long sessID, short *sessNum, DBAsyncParmBlkPtr asyncPB)
  270.  THREEWORDINLINE(0x303C, 0x0605, 0xA82F);
  271. extern pascal OSErr DBSend(long sessID, Ptr text, short len, DBAsyncParmBlkPtr asyncPB)
  272.  THREEWORDINLINE(0x303C, 0x0706, 0xA82F);
  273. extern pascal OSErr DBSendItem(long sessID, DBType dataType, short len, short places, short flags, void *buffer, DBAsyncParmBlkPtr asyncPB)
  274.  THREEWORDINLINE(0x303C, 0x0B07, 0xA82F);
  275. extern pascal OSErr DBExec(long sessID, DBAsyncParmBlkPtr asyncPB)
  276.  THREEWORDINLINE(0x303C, 0x0408, 0xA82F);
  277. extern pascal OSErr DBState(long sessID, DBAsyncParmBlkPtr asyncPB)
  278.  THREEWORDINLINE(0x303C, 0x0409, 0xA82F);
  279. extern pascal OSErr DBGetErr(long sessID, long *err1, long *err2, Str255 item1, Str255 item2, Str255 errorMsg, DBAsyncParmBlkPtr asyncPB)
  280.  THREEWORDINLINE(0x303C, 0x0E0A, 0xA82F);
  281. extern pascal OSErr DBBreak(long sessID, Boolean abort, DBAsyncParmBlkPtr asyncPB)
  282.  THREEWORDINLINE(0x303C, 0x050B, 0xA82F);
  283. extern pascal OSErr DBGetItem(long sessID, long timeout, DBType *dataType, short *len, short *places, short *flags, void *buffer, DBAsyncParmBlkPtr asyncPB)
  284.  THREEWORDINLINE(0x303C, 0x100C, 0xA82F);
  285. extern pascal OSErr DBUnGetItem(long sessID, DBAsyncParmBlkPtr asyncPB)
  286.  THREEWORDINLINE(0x303C, 0x040D, 0xA82F);
  287. extern pascal OSErr DBKill(DBAsyncParmBlkPtr asyncPB)
  288.  THREEWORDINLINE(0x303C, 0x020E, 0xA82F);
  289. extern pascal OSErr DBGetNewQuery(short queryID, QueryHandle *query)
  290.  THREEWORDINLINE(0x303C, 0x030F, 0xA82F);
  291. extern pascal OSErr DBDisposeQuery(QueryHandle query)
  292.  THREEWORDINLINE(0x303C, 0x0210, 0xA82F);
  293. extern pascal OSErr DBStartQuery(long *sessID, QueryHandle query, DBStatusUPP statusProc, DBAsyncParmBlkPtr asyncPB)
  294.  THREEWORDINLINE(0x303C, 0x0811, 0xA82F);
  295. extern pascal OSErr DBGetQueryResults(long sessID, ResultsRecord *results, long timeout, DBStatusUPP statusProc, DBAsyncParmBlkPtr asyncPB)
  296.  THREEWORDINLINE(0x303C, 0x0A12, 0xA82F);
  297. extern pascal OSErr DBResultsToText(ResultsRecord *results, Handle *theText)
  298.  THREEWORDINLINE(0x303C, 0x0413, 0xA82F);
  299. extern pascal OSErr DBInstallResultHandler(DBType dataType, DBResultHandlerUPP theHandler, Boolean isSysHandler)
  300.  THREEWORDINLINE(0x303C, 0x0514, 0xA82F);
  301. extern pascal OSErr DBRemoveResultHandler(DBType dataType)
  302.  THREEWORDINLINE(0x303C, 0x0215, 0xA82F);
  303. extern pascal OSErr DBGetResultHandler(DBType dataType, DBResultHandlerUPP *theHandler, Boolean getSysHandler)
  304.  THREEWORDINLINE(0x303C, 0x0516, 0xA82F);
  305.  
  306. #ifdef __CFM68K__
  307. #pragma lib_export off
  308. #endif
  309.  
  310. #if GENERATINGPOWERPC
  311. #pragma options align=reset
  312. #endif
  313.  
  314. #ifdef __cplusplus
  315. }
  316. #endif
  317.  
  318. #endif /* __DATABASEACCESS__ */
  319.